{ open Parser }
let digit = ['0'-'9']

rule token = parse
  [' ' '\t' '\r' '\n'] { token lexbuf }
| "/*"      { comment lexbuf }
| '('       { LPAREN }
| ')'       { RPAREN }
| '{'       { LBRACE }
| '}'       { RBRACE }
| '['       { LLIST }
| ']'       { RLIST }
| "<<"      { LVECTOR }
| ">>"      { RVECTOR }
| ';'       { SEMI }
| ','       { COMMA }
| '!'       { NOT }
| '+'       { PLUS }
| '-'       { MINUS }
| '*'       { TIMES }
| '/'       { DIVIDE }
| '%'       { REMIND }
| '&'       { LAND }
| '|'       { LOR }
| '.'       { INNERP }
| '"'       { QUOT }
| ":="      { ASSIGN }
| "=="      { EQ }
| "!="      { NEQ }
| '<'       { LT }
| "<="      { LEQ }
| ">"       { GT }
| ">="      { GEQ }
| "if"      { IF }
| "else"    { ELSE }
| "elseif"  { ELSEIF }
| "endif"   { ENDIF }
| "with"    { WITH }
| "do"      { DO }
| "done"    { DONE }
| "then"    { THEN }
| "float"   { FLOAT }
| "int"     { INT }
| "vector"  { VECTOR }
| "string"  { STR }
| "randInt "    { RINT }
| "randFloat"   { RFLOAT }
| "list"          { LIST }
| digit+ as lxm { LINT(int_of_string lxm) }
| digit+ ('.' digit*)? (['e' 'E'] ['+' '-']? digit+)? as lxm { LFLOAT(float_of_string (lxm)) }
| ['a'-'z' 'A'-'Z']['a'-'z' 'A'-'Z' '0'-'9' '_']* as lxm { ID(lxm) }
| '"' ([^'"']* as lxm) '"' { LSTR(lxm) }
| eof       { EOF }
| _ as char { raise (Failure("illegal character " ^ Char.escaped char)) }

and comment = parse
  "*/" { token lexbuf }
| _    { comment lexbuf }
